package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.dao.impl.ExtentDaoImpl;
import cn.topevery.garden.dal.dao.impl.GreLandDaoImpl;
import cn.topevery.garden.dal.dao.impl.GreTreeDaoImpl;
import cn.topevery.garden.dal.dao.impl.GreTreeFamousDaoImpl;
import cn.topevery.garden.dal.logic.*;
import cn.topevery.garden.entity.po.Extent;
import cn.topevery.garden.entity.query.*;
import hw.topevery.framework.entity.KeyValue;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 地图监测
 *
 * @author code -generate
 * @created 2021 -08-25 09:59:46
 * @date 2021 -08-06
 */
@Api(tags = "地图监测接口")
@RestController
@RequestMapping("/mapMonitor")
public class MapMonitorController extends BaseController {

    @Autowired
    PersonLogic personLogic;

    @Autowired
    CarLogic carLogic;

    @Autowired
    FacilitiesLogic facilitiesLogic;

    @Autowired
    BotanyTreeInfoLogic botanyTreeInfoLogic;

    @Autowired
    ScheduleRecordLogic scheduleRecordLogic;

    @Autowired
    GreLandDaoImpl greLandDao;

    @Autowired
    GreTreeFamousDaoImpl greTreeFamousDao;

    @Autowired
    GreTreeDaoImpl greTreeDao;

    @Autowired
    ExtentDaoImpl extentDao;





    /**
     * 统计数量
     *
     * @param query the query
     * @return count list
     * @author wenzhao.lin
     * @created 2021 -08-25 09:59:46
     */
    @ApiOperation(value = "统计数量")
    @PostMapping("/getCountList")
    public JsonResult getCountList(@RequestBody MapMonitorQuery query) {
       Map map = new HashMap();

       // 人员数量
        Map personCount = personLogic.getCount(query.getName(), StringUtils.isNotBlank(query.getSectionId())?Integer.valueOf(query.getSectionId()):null, null);

        // 车辆数量
        Map carCount = carLogic.getCount(query.getName(), StringUtils.isNotBlank(query.getSectionId())?Integer.valueOf(query.getSectionId()):null, null);
        // 设备设施数量
        Map facilitiesCount = facilitiesLogic.getCount(query.getName(),StringUtils.isNotBlank(query.getSectionId())?Integer.valueOf(query.getSectionId()):null,null);

        // 设备古树名木数量
//        Map treeCount = botanyTreeInfoLogic.getCount(query.getName(), query.getExtentId(), null);

        Map landCount = greLandDao.getCount(null,query.getSectionId());

        Map famousCount = greTreeFamousDao.getCount(null,query.getSectionId());

        Map treeCount = greTreeDao.getCount(null,query.getSectionId());

       map.put("personCount", personCount);
       map.put("carCount", carCount);
       map.put("facilitiesCount", facilitiesCount);
       map.put("landCount", landCount);
       map.put("famousCount", famousCount);
       map.put("treeCount", treeCount);
        return JsonResult.ok(map);
    }

    /**
     * 描述 获取列表
     *
     * @param query the query
     * @return the data list
     * @author wenzhao.lin
     * @created 2021 -08-25 09:59:47
     */
    @ApiOperation(value = "获取列表")
    @PostMapping("/getDataList")
    public JsonResult getDataList(@RequestBody MapMonitorQuery query) {
        List list = new ArrayList();

        switch (query.getSelectType()){
            case 1: list = personLogic.getPersonListByType(query.getName(), query.getExtentId(), Integer.parseInt(query.getType()));break;
            case 2: list = carLogic.getCarListByType(query.getName(), query.getExtentId(),Integer.parseInt(query.getType()));break;
            case 3: list = facilitiesLogic.getFacilitiesListByType(query.getName(), query.getExtentId(), query.getType());break;
            case 4: list = new ArrayList();break;
            case 5: list = new ArrayList();break;
            case 6: list = botanyTreeInfoLogic.getListByType(query.getName(), query.getExtentId(), query.getType());break;

            case 8:
                GreLandQuery greLandQuery = new GreLandQuery();
                greLandQuery.setPageSize(1000);
                greLandQuery.setBigClassId(query.getType());
                list = greLandDao.listPage(greLandQuery).records;break;
            case 9:
                GreTreeFamousQuery greTreeFamousQuery = new GreTreeFamousQuery();
                greTreeFamousQuery.setPageSize(1000);
                greTreeFamousQuery.setTreeKind(query.getType());
                list = greTreeFamousDao.getDateList(greTreeFamousQuery).records;break;
            case 10:
                final GreTreeQuery greTreeQuery = new GreTreeQuery();
                greTreeQuery.setPageSize(1000);
                greTreeQuery.setTreeKind(query.getType());
                list = greTreeDao.listPage(greTreeQuery).records;break;

            default:break;
        }
        return JsonResult.ok(list);
    }

    /**
     * 描述 获取类型列表
     *
     * @param query the query
     * @return the type list
     * @author wenzhao.lin
     * @created 2021 -08-27 09:18:08
     */
    @ApiOperation(value = "获取类型列表")
    @PostMapping("/getTypeList")
    public JsonResult getTypeList(@RequestBody MapMonitorQuery query) {
        List list = new ArrayList();



        switch (query.getSelectType()){
            case 1: list = personLogic.getPersonTypeList(query.getName(), StringUtils.isNotBlank(query.getSectionId())?Integer.valueOf(query.getSectionId()):null);break;
            case 2: list = carLogic.getCarTypeList(query.getName(), StringUtils.isNotBlank(query.getSectionId())?Integer.valueOf(query.getSectionId()):null);break;
            case 3: list = facilitiesLogic.getTypeList(query.getName(), StringUtils.isNotBlank(query.getSectionId())?Integer.valueOf(query.getSectionId()):null);break;
            case 4: list = new ArrayList();break;
            case 5: list = new ArrayList();break;
            case 6: list = botanyTreeInfoLogic.getTypeList(query.getName(), query.getExtentId());break;

            case 8: list = greLandDao.getTypeList(query.getSectionId());break;
            case 9: list = greTreeFamousDao.getTypeList(query.getSectionId());break;
            case 10: list = greTreeDao.getTypeList(query.getSectionId());break;

            default:break;
        }
        return JsonResult.ok(list);
    }


    /**
     * 获取当班情况
     *@返回值
     *@创建人  peng.tian
     *@创建时间  2021/12/29
     */
    @PostMapping("/getExtentWorkPersonAndCarInfo")
    public JsonResult getExtentWorkPersonAndCarInfo(@RequestBody ScheduleRecordQuery query){
        return JsonResult.ok(scheduleRecordLogic.getExtentWorkPersonAndCarInfo(query));
    }

    /**
     * 获取当班情况
     *@返回值
     *@创建人  peng.tian
     *@创建时间  2021/12/29
     */
    @PostMapping("/getExtentWorkInfo")
    public JsonResult getExtentWorkInfo(@RequestBody ScheduleRecordQuery query){
        return JsonResult.ok(scheduleRecordLogic.getExtentWorkInfo(query));
    }

    /**
     * 获取当班对象列表
     *@返回值
     *@创建人  peng.tian
     *@创建时间  2021/12/29
     */
    @PostMapping("/getExtentWorkObjList")
    public JsonResult getExtentWorkObjList(@RequestBody ScheduleRecordQuery query){
        return JsonResult.ok(scheduleRecordLogic.getExtentWorkObjList(query));
    }


    /**
     * 获取对象班次工作情况
     *@返回值
     *@创建人  peng.tian
     *@创建时间  2021/12/29
     */
    @PostMapping("/getObjShiftWorkInfo")
    public JsonResult getObjShiftWorkInfo(@RequestBody ScheduleRecordQuery query){
        return JsonResult.ok(scheduleRecordLogic.getObjShiftWorkInfo(query));
    }


    /**
     * 获取对象任务完成情况
     *@返回值
     *@创建人  peng.tian
     *@创建时间  2021/12/29
     */
    @PostMapping("/getObjTaskInfo")
    public JsonResult getObjTaskInfo(@RequestBody ScheduleRecordQuery query){
        return JsonResult.ok(scheduleRecordLogic.getObjTaskInfo(query));
    }

    /**
     * 获取对象工作的片区
     *@返回值
     *@创建人  peng.tian
     *@创建时间  2021/12/29
     */
    @PostMapping("/getObjWorkExtent")
    public JsonResult getObjWorkExtent(@RequestBody ScheduleRecordQuery query){
        return JsonResult.ok(scheduleRecordLogic.getObjWorkExtent(query));
    }

    /**
     * 获取对象工作任务的设施
     *@返回值
     *@创建人  peng.tian
     *@创建时间  2021/12/29
     */
    @PostMapping("/getObjWorkTaskFacilities")
    public JsonResult getObjWorkTaskFacilities(@RequestBody ScheduleRecordQuery query){
        return JsonResult.ok(scheduleRecordLogic.getObjWorkTaskFacilities(query));
    }
}
